package org.common.utils.database.entity;
import org.common.utils.database.mapper.AbstractMapper;
import java.util.List;

public class AdventureHonorMapper extends AbstractMapper<AdventureHonor> {

    private static final String INSERT_TEMPLATE = "insert into `adventure_honor` (`id`, `honor_need`, `drop`, `key`) values (?, ?, ?, ?)";

    private static final String UPDATE_TEMPLATE  = "update `adventure_honor` set `id` = ?, `honor_need` = ?, `drop` = ?, `key` = ? where `id` = ?";

    private static final String DELETE_TEMPLATE  = "delete from `adventure_honor` where `id` = ?";

    private static final String SELECT_TEMPLATE = "select `id`, `honor_need`, `drop`, `key` from `adventure_honor` where ";

    @Override
    public List<AdventureHonor> select(String whereString , List<Object> params) {
        return executeList(SELECT_TEMPLATE , whereString , params, (resultSet -> {
            AdventureHonor object = new AdventureHonor();
            object.setId(resultSet.getInt(1));
            object.setHonorNeed(resultSet.getInt(2));
            object.setDrop(resultSet.getString(3));
            object.setKey(resultSet.getInt(4));
            return object;
        }));
    }

    @Override
    public int insert(AdventureHonor object) {
        return insert(List.of(object))[0];
    }

    @Override
    public int[] insert(List<AdventureHonor> list) {
        return executeBatch(INSERT_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getHonorNeed());
            preparedStatement.setObject(3 , object.getDrop());
            preparedStatement.setObject(4 , object.getKey());
        });
    }

    @Override
    public int update(AdventureHonor object) {
        return update(List.of(object))[0];
    }

    @Override
    public int[] update(List<AdventureHonor> list) {
        return executeBatch(UPDATE_TEMPLATE , list , (preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
            preparedStatement.setObject(2 , object.getHonorNeed());
            preparedStatement.setObject(3 , object.getDrop());
            preparedStatement.setObject(4 , object.getKey());
            preparedStatement.setObject(5 , object.getId());
        });
    }

    @Override
    public int delete(AdventureHonor object) {
        return delete(List.of(object))[0];
    }

    @Override
    public int[] delete(List<AdventureHonor> list) {
        return executeBatch(DELETE_TEMPLATE , list , ((preparedStatement, object) -> {
            preparedStatement.setObject(1 , object.getId());
        }));
    }
}
